package com.example.send.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 广播模式
 */
@Configuration
public class RabbitmqFanoutConfig {

    public static final String FANOUT_EXCHANGE ="fanout_exchange";

    public static final String SMS_FANOUT_QUEUE ="sms_fanout_queue";
    public static final String EMAIL_FANOUT_QUEUE ="email_fanout_queue";
    public static final String WECHAT_FANOUT_QUEUE ="wechat_fanout_queue";


    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(FANOUT_EXCHANGE, true, false);
    }

    @Bean
    public Queue smsFanoutQueue(){
        return new Queue(SMS_FANOUT_QUEUE);
    }

    @Bean
    public Queue emailFanoutQueue(){
        return new Queue(EMAIL_FANOUT_QUEUE);
    }

    @Bean
    public Queue wechatFanoutQueue(){
        return new Queue(WECHAT_FANOUT_QUEUE);
    }

    @Bean
    public Binding smsBinding(){
        return BindingBuilder.bind(smsFanoutQueue()).to(fanoutExchange());
    }

    @Bean
    public Binding emailBinding(){
        return BindingBuilder.bind(emailFanoutQueue()).to(fanoutExchange());
    }

    @Bean
    public Binding wechatBinding(){
        return BindingBuilder.bind(wechatFanoutQueue()).to(fanoutExchange());
    }

}
